"""
请求日志 VO
"""

import utils.enum_utils as enum
from models import (
    VOBase,
    VOPage,
)
from models.other.request_info import (
    RequestInfo,
    RequestRoute,
    ResponseInfo,
)
from utils.data_utils.special import ObjectIdStr
from utils.mock_utils import Demo
from utils.validator_utils.pydantic_validator.field import (
    CharField,
    DecimalField,
    IntegerField,
    NormalField,
)


class RequestLogListVO(VOBase):
    """ 请求日志 | 列表 | VO """

    request_log_id: ObjectIdStr = CharField(..., title="请求日志 ID（ObjectId 字符串）", examples=[Demo.id])

    ip: str = CharField(..., title="IP 地址", min_length=7, max_length=15, examples=[Demo.ip])
    method: enum.Method = CharField(..., title="请求方法")
    path: str = CharField(..., title="请求路径")
    path_format: str = CharField(..., title="请求路径格式")
    request_id: str = CharField(..., title="当前线程的请求 ID", examples=[Demo.request_id])
    request_time: str = CharField(..., title="访问时间", min_length=19, max_length=19, examples=[Demo.dt_str_full])
    status_code: enum.HTTPStatusCode = IntegerField(..., title="响应状态码", examples=[Demo.status_code])
    summary: str = CharField(..., title="路由描述")
    user_id: ObjectIdStr | None = CharField(..., title="用户 ID（ObjectId 字符串）", examples=[Demo.id])


class RequestLogDetailVO(RequestLogListVO):
    """ 请求日志 | 详情 | VO """

    request_info: RequestInfo = NormalField(..., title="请求信息")
    response_info: ResponseInfo = NormalField(..., title="响应信息")
    response_time: str = CharField(..., title="响应时间", min_length=19, max_length=19, examples=[Demo.dt_str_full])
    route_info: RequestRoute = NormalField(..., title="请求路由信息")
    use_time: float = DecimalField(..., title="使用时间（秒）")


class RequestLogListPage(VOPage[RequestLogListVO]):
    """ 请求日志 | 列表 | 分页 """
